<?php
// 本类由系统自动生成，仅供测试用途
namespace Admin\Controller;
use Think\Controller;
class UserController extends CommonController {
    public function index(){
             $Data= M('admin');
              $result= $Data->order('postdtm desc')->select(); 
              $this->assign('page',$result);//留言总数
               $this->display();
    }
 
     public function add(){
     
     if(IS_POST){
    
              $m=M('admin');
             $data['password']=md5(sha1($_POST['password']));
             $data['username']=$_POST['username'];
             $data['type']=$_POST['type'];
             $data['postdtm']=date('Y-m-d');
             $count=$m->add($data);
       
             if($count>0){
                $this->success('数据修改成功',U('user/index'));
              }else{
                $this->error('数据修改失败');
              }
      }else{
      
      $this->error('非法操作！！！');
      }
             
    }
     
     public function del(){
			$m=M('admin');
			$id=$_GET['id'];
			if($id>1){
        $count=$m->delete($id);
			if($count>0){
				$this->success('数据删除成功');
			}else{
				$this->error('数据删除失败');
			}
			}else{
			
			$this->error('站长你也敢删？？？');
			}
			
		}
		
		public function modify(){
		         if(IS_POST)
     {        
            
                $m=M('admin');
                $id['id']=$_POST['id'];
                //$this->success('数据修改成功','index');
                if($_POST['password']!==''){
                $data['username']=$_POST['username'];
                $data['password']=md5(sha1($_POST['password']));
                }else{
                 $data['username']=$_POST['username'];
                }
                $count=$m->where($id)->save($data);
                if($count>0){
                  $this->ajaxReturn("修改数据成功 !",'eval');
                  }else{
                  $this->ajaxReturn("修改失败！",'eval');
             }
      } elseif(IS_GET){
        $m=M('admin');
        $id['id']=$_GET['id'];
        $data=$m->where($id)->find(); 
        $this->assign('dat',$data);//留言总数
        $this->display();
     }
      else{
      
        $this->error('非法操作哦！');
         }
   } 
   
   
}